package com.adv.util;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;

public class EncryptorUtil {

	private static final StandardPBEStringEncryptor encryptor;

	static {
		encryptor = new StandardPBEStringEncryptor();
		EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
		config.setAlgorithm("PBEWithMD5AndDES");
		config.setPassword("3eUCyp9Sw==azL9H62rgZ+TE");
		encryptor.setConfig(config);
	}

	public static final String encrypt(String str) {
		return encryptor.encrypt(str);
	}

	public static final String decrypt(String str) {
		return encryptor.decrypt(str);
	}

	public static void main(String[] args) {
		String str = "1q2w3e4r5t~!@";
		String encrypt = encrypt(str);
		String decrypt = decrypt(encrypt);
		System.out.println(str + " -> " + encrypt);
		System.out.println(decrypt + " -> " + encrypt);
	}
}
